package com.bestdreamer.predicate;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;

public class ListFilter {



    public static <E> List<E> filter(List<E> list, Predicate<E> pred){
        List<E> retList = new ArrayList<>();
        for(E e : list){
            if(pred.test(e)){
                retList.add(e);
            }
        }
        return retList;
    }

    public static <T,R> List<R> map(List<T> list, Function<T,R> mapper){
        List<R> retList = new ArrayList<>();
        for(T e : list){
            retList.add(mapper.apply(e));
        }
        return retList;
    }

}
